package model

import "server/share/config"

// 竞技场
type RoleArena struct {
	Cycle int32 `json:"ID" bson:"cycle"`
	Score int32 `json:"score" bson:"score"`
	Rank  int32 `json:"rank" bson:"rank"`
	//Defend   int32 `json:"defend" bson:"defend"` //防守阵容
	Week     int32 `json:"week" bson:"week"`
	MaxScore int32 `json:"maxScore" bson:"MaxScore"`
	MaxRank  int32 `json:"maxRank" bson:"MaxRank"`
	Level    int32 `json:"level" bson:"level"` //当前段位
}

//	func (this *Role) GetOrCreateArean() *RoleArena {
//		if this.Arena == nil {
//			return &RoleArena{MaxRank: -1, Rank: -1}
//		}
//		r := *this.Arena
//		return &r
//	}
func (this *RoleArena) Copy() *RoleArena {
	if this == nil {
		return &RoleArena{}
	}
	r := *this
	return &r
}
func (this *RoleArena) Reset(cycle int32) {
	this.Cycle = cycle
	this.Score = 0
	this.Level = 0
	this.Rank = -1
	this.Week = 0
	this.MaxScore = 0
	this.MaxRank = -1
}

func (this *RoleArena) Upgrade() (r int32) {
	for {
		i := this.Level + 1
		if c := config.Data.ArenaRankConfig[i]; c != nil && this.Score >= c.RankStart && (c.RankEnd == 0 || this.Score <= c.RankEnd) {
			r += 1
			this.Level = i
		} else {
			break
		}
	}
	return
}
